<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="yaodian100" uri="http://www.yaodian100.com/jsp/yaodian100" %>
<%@ page import="com.yaodian100.core.common.utils.ServerValue"%>
<%@ include file="/taglibs.jsp"%> 
<link rel="stylesheet" href="/css/jquery.tooltip.css" />
<link rel="stylesheet" type="text/css" media="screen" href="/css/ui.jqgrid.css" />
<link href="/css/ddaccordion.css" rel="stylesheet" type="text/css" media="screen" />
<c-rt:set var="midContextPath" value='<%=ServerValue.getMidContextPath()%>'/>
<script src="/js/jquery.tooltip.min.js" type="text/javascript"></script>
<script src="/js/grid.locale-en.js" type="text/javascript"></script>
<script src="/js/jquery.jqGrid.min.js" type="text/javascript" charset="UTF-8"></script>
<s:url var="supplierPops" value="/json/supplierPops.do"/>
<s:url var="brandPops" value="/json/brandPops.do"/>
<script type="text/javascript" charset="UTF-8" src="/js/jquery.alphanumeric.js"></script>
	<script language="javascript">
		var content;
		var qry_target = '01';
		$().ready( function() {
			if ( "" == "${productIdParam}" )
				$("#productIdParam").val("可以用逗号输入商品编号查询").css("color","#aaa");
			
			$("#productIdParam").focus(function(){
				if($("#productIdParam").val()=='可以用逗号输入商品编号查询')
					$("#productIdParam").val("").css("color","#000");
				$("#productIdParam").attr('class','focus-ipt ipt-w20');
			}).blur(function(){
				if($("#productIdParam").val()=='')
					$("#productIdParam").val("可以用逗号输入商品编号查询").css("color","#aaa");
				$("#productIdParam").attr('class','ipt-w20');
			});
			 
			//$("#productIdParam").numeric({allow:","});
			$("#supplierIdParam").numeric();
			$("#getSupplier").click(function() {
				//qry_target = 'member';
				doAR('${supplierPops}', 'dialog'); 
				openDialog('供应商搜寻',content, 550, 440);
			});	

			//$("#brandIdParam").numeric();
			$("#getBrand").click(function() {
				doAR('${brandPops}', 'dialog'); 
				openDialog('品牌搜寻',content, 550, 440);
			});	
					
			$("tr[id*='tdDesc_']").tooltip(); 
			$("#productForm").submit(function(){
				if ( 0 == $(":checkbox[name='prdtDelete']:checked").size() ){
					alert("请勾择要修改的商品");
					return false;
				} 
				if ( "" == $("#productAttribute").val() ){
					alert("请选择销售状态");
					return false;
				}
				return true;
			});
			//load default value
			if ( "" != "${categoryLevel1Param}"){ 
				$('#elementSelect').find('option').remove().end();
				$("#categorySelect option[value='${categoryLevel1Param}']").attr('selected', 'selected');  
				$.post("${midContextPath}/category/getProductCategory.do",{categoryid:"${categoryLevel1Param}"},elementSelectCallback,"json");
			}
			
			$("#categorySelect").change(function(){
				if ( "" != $(this).val()  ){
					$.ajax({
					    url: '${midContextPath}/category/getProductCategory.do',
					    type: 'post',
					    dataType: 'json',
					    data: {categoryid:$(this).val(), callback: 'elementSelectCallback'},
					    cache: false,
					    beforeSend: function(xhr) {
								$('#elementSelect').find('option').remove().end();
					    },
					    complete:function(){
					    },
					    success: function( strData ){
					    	elementSelectCallback(strData);
						}
					});
				}
			});		
		});
		function elementSelectCallback(categories){
			$('#elementSelect').append($("<option></option>").attr("value","").text("--请选择--"));
			for( var i = 0 ; i < categories.length; i++ ){
					$('#elementSelect').append($("<option></option>").attr("value",categories[i].id).text(categories[i].name));
			}
			if ( "" != "${categoryLevel2Param}" )
				$("#elementSelect option[value='${categoryLevel2Param}']").attr('selected', 'selected');
		}	
		function replaceProductIdParam(){
			if($("#productIdParam").val()=='可以用逗号输入商品编号查询')
				$("#productIdParam").val("");
		}
	</script>
<h1>商品管理<br/>
<div class="f-link"><a href="add.do">新增商品</a></div>
</h1>
<s:actionerror />
<s:actionmessage />
<s:fielderror />
<br/>
<div class="data-form"><s:form action="list.do" method="post">
	<b>商品编号：</b>
	<input name="productIdParam" id="productIdParam" type="text" title="商品编号" size="70" value="${productIdParam}">
	<b>商品名称：</b>
	<input name="productNameParam" id="productNameParam" type="text" title="商品名称" size="30" value="${productNameParam}">
	<br/>	
	<b>商品型态：</b>
	<select name="productTypeParam" id="productTypeParam" title="商品型态">
		<option value="" ${empty productTypeParam ? 'selected': ''}>全部</option>
		<option value="0" ${productTypeParam=='0' ? 'selected': ''}>一般</option>
		<option value="1" ${productTypeParam=='1' ? 'selected': ''}>预购</option>
		<option value="2" ${productTypeParam=='2' ? 'selected': ''}>赠品</option>
		<option value="3" ${productTypeParam=='3' ? 'selected': ''}>配件</option>
		<option value="7" ${productTypeParam=='7' ? 'selected': ''}>限定立即购买商品</option>
	</select>
  <b>销售状态：</b> 
  <s:select name="productAttributeParam" list="attributeMenu.options" listKey="key"  headerKey="" headerValue="全部" listValue="value.name"/>
  <b>供应商编号：</b>
	<s:textfield name="supplierParam" id="supplierIdParam" maxlength="6"/>
	<img class="ui-icon ui-icon-search" src="/images/none.gif" style="height:16px; width:16px; position:relative; display:inline;" 
		id="getSupplier"/>  
	<br/>	
	<b>品牌：</b>
	<s:textfield name="brandParam" id="brandIdParam"/>
	<img class="ui-icon ui-icon-search" src="/images/none.gif" style="height:16px; width:16px; position:relative; display:inline;" 
		id="getBrand"/>  
	<b>主分类：</b>
	<select id="categorySelect" name="categoryLevel1Param">
			<option value="">--请选择--</option>
      	<c-rt:forEach items="${rootCategories}" var="category">
			<option value="${category.id}">${category.name}</option>
		</c-rt:forEach>
   </select>
   <select id="elementSelect" name="categoryLevel2Param">
   	<option value="">--请选择--</option>
   </select> 
   <b>采购模式：</b>
   <input name="scmParam" type="radio" value="" <c-rt:if test="${empty scmParam}">checked="checked"</c-rt:if>/>不限
	 <input name="scmParam" type="radio" value="N" <c-rt:if test="${scmParam eq 'N'}">checked="checked"</c-rt:if>/>入仓
	 <input name="scmParam" type="radio" value="B" <c-rt:if test="${scmParam eq 'B'}">checked="checked"</c-rt:if>/>BO
   <input name="scmParam" type="radio" value="Y" <c-rt:if test="${scmParam eq 'Y'}">checked="checked"</c-rt:if>/>SCM        		  		
	<input type="button" value="搜寻" onclick="replaceProductIdParam();this.form.submit();" />
</s:form>
</div>
<p></p>
<br/><br/><br/>
<s:form action="editProductAttribute.do" method="post" id="productForm">
<table class="tb-1" width="100%">
	<thead>
		<tr>
      <th>#</th>
			<th>商品图</th>
			<th>商品编号</th>
			<th>商品名称</th>
			<th>商品成本</th>
			<th>厂商建议售价</th>
			<th>
				建立者<br/>
				建立日期<br/>
				修改者<br/>
				修改日期</th>
			<th>商品型态</th>
			<th>销售状态</th>
			<th>上传图片</th>
      <th>商品规格</th>
      <th>上下架</th>
      <!-- <th>复制</th> -->
		</tr>
	</thead>
	<tbody>			 		 
    <c-rt:forEach items="${products}" var="product" varStatus="rows_index">            
			<tr class="${rows_index.count % 2 == 0 ? 'bg-yl' : ''}" id="tdDesc_${rows_index.count}" title="${not empty rsmap ?rsmap[product.productId]:''}">
				<td><input name="prdtDelete" type="checkbox" value="${product.productId}" /></td>
				<td>
					<yaodian100:productImg productId="${product.productId}" postfix="m75" />
				</td>
				<td><a href="edit.do?productId=${product.productId}" />${product.productId}</a></td>
				<td>${product.productName}</td>
				<td><fmt:formatNumber value="${product.productCost}" pattern="#####0.00"/></td>
				<td><fmt:formatNumber value="${product.listPrice}" pattern="#####0.0"/></td>
				<td>
				
					${product.createUser}<br/>
					<fmt:formatDate value="${product.createDate}" pattern="yyyy-MM-dd HH:mm:ss" /><br/>
					${product.modifyUser}<br/>
				<fmt:formatDate value="${product.modifyDate}" pattern="yyyy-MM-dd HH:mm:ss" /></td>
				<td>
					<c-rt:if test="${product.productType eq '0'}">一般</c-rt:if>
					<c-rt:if test="${product.productType eq '1'}">预购</c-rt:if>
					<c-rt:if test="${product.productType eq '2'}">赠品</c-rt:if>
					<c-rt:if test="${product.productType eq '3'}">配件</c-rt:if>
					<c-rt:if test="${product.productType eq '7'}">限定立即购买商品</c-rt:if>
				</td>
				<td>${attributeMenu.options[product.isDelete].name}</td>				
				<td><a href="<%=ServerValue.getMidContextPath()%>/image/edit.do?productId=${product.productId}" />上传</a></td>
        <td><a href="spec.do?productId=${product.productId}" />修改</a></td>
				<td><a href="<%=ServerValue.getMidContextPath()%>/shelf/list.do?productId=${product.productId}" />上下架</a></td>
				<!-- <td><a href="copy.do?productId=${product.productId}" />复制</a></td> -->
			</tr>
		</c-rt:forEach>
	</tbody>
</table>
<br />
<s:select id="productAttribute" name="productAttribute" list="attributeMenu.options" listKey="key"  listValue="value.name" headerKey="" headerValue="---请选择销售状态---"/>
<input type="submit" value="批次修改"/>
<yaodian100:pageutil link="list.do" pagerObj="${pager}" />
</s:form> 	